package com.gexiaobao.pigeon.ui.fragment.mine.organization.activity

import android.os.Bundle
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.BaseActivity
import com.gexiaobao.pigeon.app.util.StatusBarUtil
import com.gexiaobao.pigeon.databinding.ActivityPassSignOrderAllBinding
import com.gexiaobao.pigeon.ui.fragment.mine.organization.detail.FragmentPassSignOrder
import com.gexiaobao.pigeon.viewmodel.OrgRaceViewModel
import com.google.android.material.tabs.TabLayout
import me.hgj.jetpackmvvm.ext.util.setOnclickNoRepeat

/**
 * @Author      : hxw
 * @Date        : 2024/7/18 10:01
 * @Describe    : 关赛报名全部订单
 */
class ActivityPassSignAllOrder : BaseActivity<OrgRaceViewModel, ActivityPassSignOrderAllBinding>() {

    private var mRaceId = 0

    override fun initView(savedInstanceState: Bundle?) {
        StatusBarUtil.setTranslucentForImageView(this, 0, null)
        mDatabind.includeBar.tvTitle.text = getString(R.string.all_order)

        mRaceId = intent.getIntExtra("raceId", 0)
        initTabLayout()
    }

    override fun onBindViewClick() {
        super.onBindViewClick()
        setOnclickNoRepeat(mDatabind.includeBar.ivBack) {
            when (it) {
                mDatabind.includeBar.ivBack -> finish()
            }
        }
    }

    private fun initTabLayout() {
        val tab1 = mDatabind.tabLayout.newTab().setText(getString(R.string.market_shop_order_list_for_fragment_layout_activity_my_order_tab_all))
        mDatabind.tabLayout.addTab(tab1)
        val tab2 = mDatabind.tabLayout.newTab().setText(getString(R.string.already_booked))
        mDatabind.tabLayout.addTab(tab2)
        val tab3 = mDatabind.tabLayout.newTab().setText(getString(R.string.checked))
        mDatabind.tabLayout.addTab(tab3)
        val tab4 = mDatabind.tabLayout.newTab().setText(getString(R.string.Additional_expenses))
        mDatabind.tabLayout.addTab(tab4)
        val tab5 = mDatabind.tabLayout.newTab().setText(getString(R.string.refunded))
        mDatabind.tabLayout.addTab(tab5)
        mDatabind.tabLayout.addOnTabSelectedListener(object : TabLayout.BaseOnTabSelectedListener<TabLayout.Tab> {
            override fun onTabReselected(p0: TabLayout.Tab) {}
            override fun onTabUnselected(p0: TabLayout.Tab) {}

            override fun onTabSelected(p0: TabLayout.Tab) {
                replaceFragments(p0.position)
            }
        })
        replaceFragments(0)
    }

    private fun replaceFragments(position: Int) {
        supportFragmentManager.beginTransaction().apply {
            when (position) {
                0 -> replace(R.id.container, FragmentPassSignOrder.newInstance(mRaceId, 0))//全部
                1 -> replace(R.id.container, FragmentPassSignOrder.newInstance(mRaceId, 1))//待审核
                2 -> replace(R.id.container, FragmentPassSignOrder.newInstance(mRaceId, 2))//已审核
                3 -> replace(R.id.container, FragmentPassSignOrder.newInstance(mRaceId, 3))//待补费
                4 -> replace(R.id.container, FragmentPassSignOrder.newInstance(mRaceId, 4))//已退费
            }
        }.commitAllowingStateLoss()
    }
}